package edu.hawaii.duedates;

import java.util.List;

/**
 * Main class for Due Dates project. Uses provided command line information to log into specified
 * lender websites and report information regarding due dates of borrowed items.
 * 
 * @author Aric West
 * @author Daniel Tian
 * 
 */
public class DueDates {

  /**
   * Main method.
   * 
   * @param args Command line input including lender argument and log in information.
   * @throws Exception Throws exceptions propagated from subroutines and LenderQuery objects.
   */
  public static void main(String[] args) throws Exception {
    DueDates dueDates = new DueDates();

    CommandLineParser clparser = new CommandLineParser(args);
    List<LenderQuery> lenderList = clparser.getLenderList();

    dueDates.printBorrowedItemsToConsole(lenderList);
  }

  /**
   * Prints out the list of borrowed items.
   * 
   * @param lenderList the list containing all the instantiated library classes
   * @throws Exception throws an exception if there was a problem getting the list of borrowed items
   */
  public void printBorrowedItemsToConsole(List<LenderQuery> lenderList) throws Exception {
    List<BorrowedItem> borrowedItems;
    
    for (LenderQuery lender : lenderList) {
      System.out.println(lender.getLenderName() + ":");

       borrowedItems = lender.getBorrowedItems();

      if (borrowedItems.isEmpty()) {
        System.out.println("There are no items checked out.");
      }
      else {
        for (BorrowedItem item : borrowedItems) {
          System.out.println(item);
        }
      }
    }
  }
}
